package com.fisher.checker.db;

import com.fisher.checker.db.dao.ProductItemDao;
import com.fisher.checker.db.entity.ProductItemEntity;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DatabaseManager {

    private final ExecutorService executor = Executors.newSingleThreadExecutor();

    public <M,T> void execute(DataOperation<M,T> operation, M param) {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                try{
                    T value = operation.execute(param);
                    operation.onCompleted(value);
                }catch (Exception e){
                    e.printStackTrace();
                    operation.onError(e);
                }


            }
        });
    }


    public interface DataOperation<T,R> {
        R execute(T obj);
        void onCompleted(R value);
        void onError(Exception e);
    }
}
